<?php
	session_start();
	
	if(isset($_SESSION["cb_redirect_url"]))
	{
		include_once(dirname(__FILE__).'/config.php');
		require_once(dirname(__FILE__).'/includes/db-core.php');
		require_once(dirname(__FILE__).'/includes/db-functions.php');
		//print_r($_GET);
		//Array ( [account] => jonelang456 [ip] => 127.0.0.1 [logintype] => 1 [notify_id] => a29813ae67da5f70c0c7c4cf866c8f9e [phonenum] => 13641648100 [pwdlevel] => 3 [session_id] => 5c586148c88197b4d466df0b8f082784 [showaccount] => jonelang456 [type] => 24 [uid] => 98863121 [sign] => b003dce7cdf8065a3a12f1de13c3d0db [sign_type] => MD5 ) 

		//userID plat platUserID platAccount userName lastLoginTime userIP

		connect_db();
		$plat = "ztgame";
		$ussql = "select * from ap_users where plat = '".$plat."' and platUserID = '".$_GET["uid"]."'";

		$uresult = mysql_query($ussql);
		if($uresult)
		{
			$urow = mysql_fetch_array($uresult);
		}
		if(!empty($urow))
		{
			$_SESSION["userid"] = $urow["userID"];
		}
		else
		{
			$isusql = "insert ap_users(plat, platUserID, platAccount, userName, lastLoginTime, userIP) values('".$plat."','".$_GET["uid"]."','".$_GET["account"]."','".$_GET["showaccount"]."','".date("Y-m-d H:i:s")."','".$_GET["ip"]."')";

			mysql_query($isusql);
			$_SESSION["userid"] = mysql_insert_id();
		}

		$_SESSION["userAccount"] = $_GET["account"];
		$_SESSION["userName"] = $_GET["showaccount"];
		//print_r($_SESSION);
		$redirecturl = $_SESSION["cb_redirect_url"];
		unset($_SESSION["cb_redirect_url"]);
		header("Location: ".$redirecturl);
	}
?>